﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.SharePoint.Administration;

namespace SLMySitesNavInjection
{
    /// <summary>
    /// Static class containing constants and helper methods
    /// </summary>
    internal static class Definitions
    {
        /// <summary>
        /// The menu options to be added to the left navigation (relative url, title)
        /// </summary>
        internal static readonly string[,] ProfilePageLinks = new[,]
            {
                {"/mypage1.aspx", "Page 1"},
                {"/mypage2.aspx", "Page 2"},
                {"/mypage3.aspx", "Page 3"}
            };

        /// <summary>
        /// Index of the link url for 2 dimensional ProfilePageLinks array
        /// </summary>
        internal const int LinkUrl = 0;

        /// <summary>
        /// Index of the link title for 2 dimensional ProfilePageLinks array
        /// </summary>
        internal const int LinkTitle = 1;

        /// <summary>
        /// The include path for the jQuery library used in the user control
        /// </summary>
        internal const string JqueryIncludePath = "/_layouts/15/SLMySitesNavInjection/jquery-1.10.1.min.js";

        /// <summary>
        /// The include path for the JavaScript used in the user control
        /// </summary>
        internal const string ControlJsIncludePath = "/_layouts/15/SLMySitesNavInjection/SLMySitesNavInjection.js";

        /// <summary>
        /// The ULS category for the My Sites Navigation Injection solution
        /// </summary>
        internal const string UlsCategory = "SLMySitesNavInjection";

        /// <summary>
        /// JavaScript template for the new menu items array
        /// </summary>
        internal const string JsTemplate = "var newNavItems = []; \n\r{0}";

        /// <summary>
        /// JavaScript + HTML for adding a new menu item to the JavaScript array
        /// </summary>
        internal const string NavItemTemplate =
            "newNavItems.push(\"<li class='static {0}'> <a tabindex='0' class='static {0} menu-item ms-core-listMenu-item ms-displayInline ms-navedit-linkNode' href='{1}'><span class='additional-background ms-navedit-flyoutArrow'><span class='menu-item-text'>{2}</span>{3}</span></a></li>\");\n\r";

        /// <summary>
        /// HTML template for the hidden span for the selected menu item
        /// </summary>
        internal const string SelectedSpan = "<span class='ms-hidden'>Currently selected</span>";

        /// <summary>
        /// Internal method to get the file version of the current assembly
        /// </summary>
        /// <returns>The assembly file version as a string</returns>
        internal static string GetAssemblyFileVersion()
        {
            var retVal = "";

            try
            {
                var assembly = System.Reflection.Assembly.GetExecutingAssembly();
                var fvi = System.Diagnostics.FileVersionInfo.GetVersionInfo(assembly.Location);
                retVal = fvi.ProductVersion;
            }
            catch (Exception ex)
            {
                //log error
                UlsHelper.WriteUlsEntry(ex, TraceSeverity.Unexpected, EventSeverity.Error, UlsCategory);
            }

            return retVal;
        }
    }
}
